package com.pet.client.common;

import java.io.File;
import java.util.List;

import com.pet.framework.constant.ATTFrameWork;
import com.pet.framework.page.ATTPage;
import com.pet.framework.page.Page;
import com.pet.framework.page.PagerFactory;
import com.pet.framework.util.BaseAction;
import com.pet.server.bo.role.RoleService;
import com.pet.server.bo.system.AdminService;
import com.pet.server.po.Campaign;
import com.pet.server.po.CampaignPosition;
import com.pet.server.po.CateBrand;
import com.pet.server.po.Constant;
import com.pet.server.po.PetSay;
import com.pet.system.constants.ATTSystem;
import com.pet.system.constants.BaseAttribute;
import com.pet.system.util.JsonUtil;

public class OperatorAction extends BaseAction {

  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Integer id;
	private RoleService roleService;
	private AdminService adminService;
	private String cate;
	private Campaign campaign;
	private List<String> brand;
	public File img3File;
	public String img3FileFileName;
	public String imgUrl;
	
	
	/**
	 * 活动页
	 * @return
	 */
	public String toCampaignImg(){
		
		setAttr("imgUrl", imgUrl);
		return SUCCESS;
	}
	
	
	/**
	 * 删除宠物说数据
	 * @return
	 */
	public String deleteCampaign(){
		Campaign v = adminService.getObject(id, Campaign.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			adminService.updateObject(v);
		}
		return SUCCESS;
	}
	
	
	/**
	 * 活动页
	 * @return
	 */
	public String searchCampaign(){
		Page page = PagerFactory.createPage();
		adminService.searchCampaign(campaign, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	/**
	 * 活动添加页
	 * @return
	 */
	public String toCampaign(){
		Campaign p=adminService.getObject(id, Campaign.class);
		List<CampaignPosition> list = roleService.searchList();
		super.setAttr(ATTFrameWork.CPLIST, list);
		super.setAttr("campaign", p);
		//sPage page  
		return SUCCESS;
	}
	
	/**
	 * 活动保存
	 * @return
	 */
	public String suCampaign(){
		Campaign p = adminService.getObject(id,Campaign.class);
		if(null==p && null!=campaign){
			adminService.savePetInfo(campaign, img3File, img3FileFileName);
		}else if(null!=campaign){
			adminService.updatePetInfo(p, campaign, img3File, img3FileFileName);
		}
		return SUCCESS;
	}
	
	
	public String cateBrand(){
		List<Constant> list = roleService.queryConstantsByPcode(BaseAttribute.BRAND_CODE, ATTSystem.LOGIC_TRUE);
		super.setAttr(BaseAttribute.LIST, list);
		return SUCCESS;
	}
	
	public String loadCateBrand(){
		List<CateBrand> list = adminService.queryCateBrand(cate);
		setAjaxData(JsonUtil.createBrandReg(list).toString());
		return SUCCESS;
	}
	public String saveCateBrand(){
		adminService.saveCateBrand(cate, brand);
		return SUCCESS;
	}

	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	public AdminService getAdminService() {
		return adminService;
	}

	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	public String getCate() {
		return cate;
	}

	public void setCate(String cate) {
		this.cate = cate;
	}

	public List<String> getBrand() {
		return brand;
	}

	public void setBrand(List<String> brand) {
		this.brand = brand;
	}
	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}
	/**
	 * @return the campaign
	 */
	public Campaign getCampaign() {
		return campaign;
	}
	/**
	 * @param campaign the campaign to set
	 */
	public void setCampaign(Campaign campaign) {
		this.campaign = campaign;
	}
	/**
	 * @return the imgUrl
	 */
	public String getImgUrl() {
		return imgUrl;
	}
	/**
	 * @param imgUrl the imgUrl to set
	 */
	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}
	
}
